<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
<script src="http://code.jquery.com/jquery-2.1.1.min.js"></script>
<script src="/jsencrypt.min.js"></script>

</head>
<body>
<form id="form" >
<div>
<input type="text" id="name" value="123456lkjasd" style="width:500px;">
</div>
<div>&nbsp;</div>
<div>
<textarea id="content" rows="5" cols="50">d</textarea>
</div>
<div>
<input type="button" onclick="jiami()" value="加密" ><input type="button" onclick="tosubmit()" value="提交解密" >
</div>
<div id="rtndiv">&nbsp;</div>
</form>
</body>
</html>
<script>
$(function(){
	
});
function jiami(){
	var encryptor = new JSEncrypt()  // 创建加密对象实例
	  //之前ssl生成的公钥，复制的时候要小心不要有空格
	  //var pubKey =  `MFwwDQYJKoZIhvcNAQEBBQADSwAwSAJBANo2FFTbQDDJ5d10GrhQprrdDfO0Qi5q7Ft/UDKRdHE6eh5o/KaehWN9Mce3aj64tWxsEhAqeAxA1eAdPRwYJyUCAwEAAQ==`
	  var pubKey = 'MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQC+u/9uyC1Py0Znp3NJzra47bzJfxCfCR9zw9mf+PRbyQ7nM4I4j/OKfVZGJaH51B5UZvS+KNRhQEFfGUFPQjRBVLFXC6MCneVJ0xev7lnzw0ZpbYNbYzB70GxjUQ1NxiMG6julEtqFPqjfRVEGb/A57LY9RhRH3a/q4w3sqKuVMQIDAQAB';
	  encryptor.setPublicKey(pubKey)//设置公钥
	  var rsaPassWord = encryptor.encrypt($("#name").val())  // 对内容进行加密
	  console.log(rsaPassWord);
	  $("#content").val(rsaPassWord);
}

function tosubmit(){
	$.post("/encrypt/decrypt",{data:$("#content").val()},function(data){
		console.log(data);
		$("#rtndiv").html(data);
	},"json");
}
</script>